package org.testis.gui.mvc.view.testdesign;

import org.testis.gui.mvc.view.*;
import org.testis.gui.mvc.utilities.Validatable;
import org.testis.gui.mvc.controller.TestDesignControllerList;
import org.testis.gui.mvc.controller.testdesign.ConditionsController;
import org.testis.gui.mvc.controller.testdesign.TestStepGroupController;
import org.testis.gui.mvc.view.labels.DefaultLabelTreeLoader;
import org.testis.gui.mvc.view.labels.ILabelTreeLoader;
import org.testis.gui.mvc.view.labels.LabelTreeNodeEditor;
import org.testis.gui.mvc.view.labels.TwoStateLabelNodeRenderer;
import org.testis.gui.mvc.utilities.ValidationUtils;
import org.testis.gui.mvc.view.labels.LabelPairSettingsView;
import org.testis.orm.labelhandler.LabelRefined;
import org.testis.utils.tree.DefaultMutableLabelNode;
import java.awt.Frame;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTree;
import javax.swing.SpinnerNumberModel;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;
import org.orm.PersistentException;

/**
 *
 * @author  Cahit Emir Erel
 */
public class TestStepGroupView extends AtofBaseDialog implements
        AbstractViewPanel, Validatable {

    private static final long serialVersionUID = 79328471L;
    private boolean m_editMode;
    private String m_windowTitle;
    private LabelPairSettingsView m_labelSettingsView;

    /** Creates new form AddTestPlanView */
    public TestStepGroupView(Frame parent,
            boolean modal,
            boolean editMode) {
        super(parent,
                modal);
        m_editMode = editMode;
        if (editMode) {
            m_windowTitle = "Edit Test Step Group";
        } else {
            m_windowTitle = "Add Test Step Group";
        }
        m_labelSettingsView = new LabelPairSettingsView();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        saveButton = new javax.swing.JButton();
        btnEditLabels = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        timeoutLabel = new javax.swing.JLabel();
        noOfRetryOnFailTextField = new javax.swing.JTextField();
        runAlwaysChoice = new java.awt.Choice();
        runAlwaysLabel = new javax.swing.JLabel();
        successPercentageLabel = new javax.swing.JLabel();
        criticalChoice = new java.awt.Choice();
        noOfRetryOnFailLabel = new javax.swing.JLabel();
        successPercentageSpinner = new JSpinner(new SpinnerNumberModel(100, //initial value
            0, //min
            100, //max
            1));
    descriptionTextField = new javax.swing.JTextField();
    nameTextField = new javax.swing.JTextField();
    descriptionLabel = new javax.swing.JLabel();
    timeoutTextField = new javax.swing.JTextField();
    invocCountLabel = new javax.swing.JLabel();
    criticalLabel = new javax.swing.JLabel();
    noOfInvocation = new javax.swing.JTextField();
    nameLabel = new javax.swing.JLabel();
    labelSettingsScrollPane = new javax.swing.JScrollPane();
    labelSettingsScrollPane.setViewportView(m_labelSettingsView);

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(m_windowTitle);
    setModal(true);
    setResizable(false);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosed(java.awt.event.WindowEvent evt) {
            formWindowClosed(evt);
        }
    });

    saveButton.setText("Save");
    saveButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveButtonActionPerformed(evt);
        }
    });

    btnEditLabels.setText("Cancel");
    btnEditLabels.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnEditLabelsActionPerformed(evt);
        }
    });

    timeoutLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    timeoutLabel.setText("Timeout:");

    noOfRetryOnFailTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    noOfRetryOnFailTextField.setText("0");
    noOfRetryOnFailTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            noOfRetryOnFailTextFieldActionPerformed(evt);
        }
    });
    noOfRetryOnFailTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            noOfRetryOnFailTextFieldFocusLost(evt);
        }
    });

    runAlwaysChoice.add("true");
    runAlwaysChoice.add("false");
    runAlwaysChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            runAlwaysChoiceItemStateChanged(evt);
        }
    });

    runAlwaysLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    runAlwaysLabel.setText("Run Always * :");

    successPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    successPercentageLabel.setText("Success Percentage * :");

    criticalChoice.add("false");
    criticalChoice.add("true");
    criticalChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            criticalChoiceItemStateChanged(evt);
        }
    });

    noOfRetryOnFailLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    noOfRetryOnFailLabel.setText("No of Retry on Fail:");

    successPercentageSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            successPercentageSpinnerStateChanged(evt);
        }
    });

    descriptionTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    descriptionTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            descriptionTextFieldActionPerformed(evt);
        }
    });
    descriptionTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            descriptionTextFieldFocusLost(evt);
        }
    });

    nameTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    nameTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            nameTextFieldActionPerformed(evt);
        }
    });
    nameTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            nameTextFieldFocusLost(evt);
        }
    });

    descriptionLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    descriptionLabel.setText("Description:");

    timeoutTextField.setEditable(false);
    timeoutTextField.setFont(new java.awt.Font("Dialog", 0, 11));

    invocCountLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    invocCountLabel.setText("Invocation Count:");

    criticalLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    criticalLabel.setText("Critical * :");

    noOfInvocation.setFont(new java.awt.Font("Dialog", 0, 11));
    noOfInvocation.setText("0");
    noOfInvocation.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            noOfInvocationActionPerformed(evt);
        }
    });
    noOfInvocation.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            noOfInvocationFocusLost(evt);
        }
    });

    nameLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    nameLabel.setText("Name * :");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(successPercentageLabel)
                .addComponent(runAlwaysLabel)
                .addComponent(noOfRetryOnFailLabel)
                .addComponent(criticalLabel)
                .addComponent(descriptionLabel)
                .addComponent(nameLabel)
                .addComponent(timeoutLabel)
                .addComponent(invocCountLabel))
            .addGap(10, 10, 10)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(runAlwaysChoice, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(noOfRetryOnFailTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                            .addComponent(successPercentageSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
                        .addGap(151, 151, 151))
                    .addComponent(descriptionTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                    .addComponent(criticalChoice, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                    .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(timeoutTextField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(noOfInvocation, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
            .addGap(892, 892, 892))
    );

    jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {noOfInvocation, noOfRetryOnFailTextField});

    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(nameLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(descriptionLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(criticalChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(criticalLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(runAlwaysChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(runAlwaysLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(successPercentageSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(successPercentageLabel))
            .addGap(15, 15, 15)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(noOfRetryOnFailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(noOfRetryOnFailLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(noOfInvocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(invocCountLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(timeoutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(timeoutLabel))
            .addGap(59, 59, 59))
    );

    jTabbedPane1.addTab("General", jPanel1);
    jTabbedPane1.addTab("Labels", labelSettingsScrollPane);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(313, Short.MAX_VALUE)
            .addComponent(saveButton)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(btnEditLabels)
            .addContainerGap())
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 435, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnEditLabels)
                .addComponent(saveButton))
            .addContainerGap())
    );

    ConditionsController.createInstance(m_editMode).initialize();
    jTabbedPane1.addTab("Conditions", ConditionsController.getInstance().getConditionView());

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed
        try {
            //controller.changeDocumentName(nameTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
    }//GEN-LAST:event_nameTextFieldActionPerformed

    private void nameTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusLost
        try {
            //controller.changeDocumentName(nameTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
    }//GEN-LAST:event_nameTextFieldFocusLost

    private void descriptionTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_descriptionTextFieldActionPerformed
        try {
            //controller.changeDocumentWidth(
            //Integer.parseInt(widthTextField.getText()));
        } catch (Exception e) {
            //  Handle exception
        }
}//GEN-LAST:event_descriptionTextFieldActionPerformed

    private void descriptionTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionTextFieldFocusLost
        try {
            //controller.changeDocumentWidth(
            //Integer.parseInt(widthTextField.getText()));
        } catch (Exception e) {
            //  Handle exception
        }
}//GEN-LAST:event_descriptionTextFieldFocusLost

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

        WindowListener[] listeners = getWindowListeners();
        for (int i = 0; i < listeners.length; i++) {
            this.removeWindowListener(listeners[i]);
        }
        this.setEnabled(false);
        this.dispose();
        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationCloseWindow();
        ConditionsController.createInstance(m_editMode).operationClose();
    }//GEN-LAST:event_formWindowClosed

    private void criticalChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_criticalChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationChangeCritical(criticalChoice.getSelectedItem());
    }//GEN-LAST:event_criticalChoiceItemStateChanged

    private void runAlwaysChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_runAlwaysChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationChangeRunAlways(runAlwaysChoice.getSelectedItem());
    }//GEN-LAST:event_runAlwaysChoiceItemStateChanged

    @Override
    public boolean validateForm() {
        boolean valid = true;
        StringBuilder builder = new StringBuilder();
        if (ValidationUtils.isEmpty(nameTextField.getText())) {
            builder.append("Name must not be empty.\n");
            valid = false;
        }
        if (!ValidationUtils.isNumeric(noOfRetryOnFailTextField.getText())) {
            builder.append("Retry count must  be integer.\n");
            valid = false;
        }
        if (!ValidationUtils.isNumeric(noOfInvocation.getText())) {
            builder.append("Invoc count must  be integer.\n");
            valid = false;
        }
        if (!valid) {
            JOptionPane.showMessageDialog(null,
                    builder.toString(),
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        return valid;
    }

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        if (!validateForm()) {
            return;
        }
        saveButton.setEnabled(false);

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("name",
                nameTextField.getText());
        params.put("description",
                descriptionTextField.getText());
        params.put("critical",
                criticalChoice.getSelectedItem());
        params.put("runAlways",
                runAlwaysChoice.getSelectedItem());
        params.put("noOfRetryOnFail",
                noOfRetryOnFailTextField.getText());
        params.put("noOfInvocationCount",
                noOfInvocation.getText());
        params.put("successPercentage",
                ((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().
                getText());

        LinkedList<String> labels = m_labelSettingsView.getSelectedLabelNames();
        params.put("labels", labels);

        LinkedHashMap<Integer, String> listOfCond = ConditionsController.getInstance().getConditionsList();

        if (listOfCond != null) {
            params.put("conditions", listOfCond);
        }

        if (m_editMode) {
            TestDesignControllerList.newInstance().getTestStepGroupController().
                    operationSaveTestStepGroup(params);
        } else {
            try {
                TestDesignControllerList.newInstance().getTestStepGroupController().operationAddTestStepGroup(
                        params);
            } catch (PersistentException ex) {
                ex.printStackTrace();
            }
        }
        this.dispose();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void successPercentageSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_successPercentageSpinnerStateChanged
        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationChangeSuccessPercentage(((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().
                getText());
    }//GEN-LAST:event_successPercentageSpinnerStateChanged

    private void noOfRetryOnFailTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noOfRetryOnFailTextFieldActionPerformed
        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationChangeNumberOfRetryOnFail(
                noOfRetryOnFailTextField.getText());
}//GEN-LAST:event_noOfRetryOnFailTextFieldActionPerformed

    private void noOfRetryOnFailTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_noOfRetryOnFailTextFieldFocusLost
        TestDesignControllerList.newInstance().getTestStepGroupController().
                operationChangeNumberOfRetryOnFail(
                noOfRetryOnFailTextField.getText());
}//GEN-LAST:event_noOfRetryOnFailTextFieldFocusLost

    private void noOfInvocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noOfInvocationActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_noOfInvocationActionPerformed

    private void noOfInvocationFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_noOfInvocationFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_noOfInvocationFocusLost
    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(
                TestStepGroupController.SHOW_ADD_TEST_STEP_GROUP)) {
            this.centerParent();
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_NAME)) {
            nameTextField.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_DESCRIPTION)) {
            descriptionTextField.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_RUN_ALWAYS)) {
            runAlwaysChoice.select(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_TIMEOUT)) {
            timeoutTextField.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_CRITICAL)) {
            criticalChoice.select(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_SUCCESS_PERCENTAGE)) {
            ((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().setText(
                    ((Byte) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_NUMBER_OF_RETRY_ON_FAIL)) {
            noOfRetryOnFailTextField.setText(
                    ((Integer) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepGroupController.CHANGE_NUMBER_OF_INVOCATION_COUNT)) {
            noOfInvocation.setText(((Integer) evt.getNewValue()).toString());
        }
    }
    private void btnEditLabelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditLabelsActionPerformed
        dispose();
    }//GEN-LAST:event_btnEditLabelsActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEditLabels;
    private java.awt.Choice criticalChoice;
    private javax.swing.JLabel criticalLabel;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JTextField descriptionTextField;
    private javax.swing.JLabel invocCountLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JScrollPane labelSettingsScrollPane;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JTextField noOfInvocation;
    private javax.swing.JLabel noOfRetryOnFailLabel;
    private javax.swing.JTextField noOfRetryOnFailTextField;
    private java.awt.Choice runAlwaysChoice;
    private javax.swing.JLabel runAlwaysLabel;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel successPercentageLabel;
    private javax.swing.JSpinner successPercentageSpinner;
    private javax.swing.JLabel timeoutLabel;
    private javax.swing.JTextField timeoutTextField;
    // End of variables declaration//GEN-END:variables
}
